<div class="layuimini-main">
    <div class="layui-form layuimini-form" lay-filter="infoForm">
        <div class="layui-form-item">
            <label class="layui-form-label ">家庭名称</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="">
                <input type="text" name="name" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">家庭简介</label>
            <div class="layui-input-block">
                <textarea name="introduction" class="layui-textarea" placeholder="请输入家庭简介"></textarea>
<!--                <input type="text" name="introduction" placeholder="请输入家庭简介" value=""-->
<!--                       class="layui-input">-->
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'miniPage'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniPage = layui.miniPage;

        axios({
            url: 'family/familyInfo',
            method: 'get'
        }).then(response => {
            console.log(response)
            let data = response.data;
            form.val("infoForm", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                "id": data.id
                ,"name": data.name
                ,"introduction": data.introduction
                ,"remark": data.remark
            });

        }).catch(error => {
            layer.msg(error);
        })

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            axios({
                url: 'family/update',
                method: 'post',
                data: data.field
            }).then(response => {
                console.log(response);
                layer.msg(response.msg, function () {
                    miniPage.hashHome();
                })

            }).catch(error => {
                layer.msg(error)
            })
            return false;
        });





    });
</script>